package sb.simple.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * swagger配置
 *
 * 与Application.java同级或通过@Import导入配置
 *
 * 访问地址=>http://host:port/swagger-ui.html
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean(value = "默认模块的接口")
    public Docket apiDefault() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("默认接口")
                .select()
                .apis(RequestHandlerSelectors.basePackage("sb.simple"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean(value = "swagger模块的接口")
    public Docket apiSwagger() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())//添加接口文档页面信息
                .groupName("swagger接口")//分组名
                .select()
                .apis(RequestHandlerSelectors.basePackage("sb.simple.swagger"))//分组api所属位置
                .paths(PathSelectors.any())
                .build();
    }

    @Bean(value = "wrapper模块的接口")
    public Docket apiWrapper() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("wrapper接口")
                .select()
                .apis(RequestHandlerSelectors.basePackage("sb.simple.wrapper"))
                .paths(PathSelectors.any())
                .build();
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("卫宁物联网数据平台服务接口文档")
                .description("接口由swagger注解生成")
                //.termsOfServiceUrl("")
                .contact("winning health")
                .version("1.0")
                .build();
    }
}
